package com.transaction.service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

@Component("materialDao")
public class MaterialDaoImpl extends HibernateDaoSupport implements MaterialDao {

	private SessionFactory mySessionFactory;

	@Resource
	@Qualifier("sessionFactory")
	public void setMySessionFactory(SessionFactory mySessionFactory) {
		this.mySessionFactory = mySessionFactory;
	}
	
	@PostConstruct
	public void setSuperSessionFactory() {
		super.setSessionFactory(mySessionFactory);
	}
	@Override
	public Integer add(MaterialDto materialDto) {
		Material material = new Material();
		material.setName(materialDto.getName());
		return (Integer)this.getHibernateTemplate().save(material);

	}
	@Override
	public void update(MaterialDto materialDto) {
		Material material = new Material();
		material.setId(materialDto.getId());
		material.setName(materialDto.getName());
		this.getHibernateTemplate().merge(material);
	}

}
